package cn.sicnu.cs.employment.rest;

import cn.sicnu.cs.employment.common.ResultInfo;
import cn.sicnu.cs.employment.common.ResultInfoUtil;
import cn.sicnu.cs.employment.common.util.BeanConvertUtils;
import cn.sicnu.cs.employment.domain.entity.BackgroundInfo;
import cn.sicnu.cs.employment.domain.vo.BackgroundInfoVo;
import cn.sicnu.cs.employment.service.IBackgroundInfoService;
import cn.sicnu.cs.employment.service.IBgAppealService;
import cn.sicnu.cs.employment.service.IEmployeeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.sicnu.cs.employment.common.util.RequestUtil.getCurrentUrl;

@Slf4j
@RestController
@RequestMapping("/bg")
@RequiredArgsConstructor
@Deprecated
public class BackgroundInfoResource {

    private final IBackgroundInfoService infoService;
    private final IBgAppealService appealService;
    private final IEmployeeService employeeService;

    /**
     * 根据员工id获取背景信息
     * 不发送id则表示员工登录，获取当前员工的
     */
    @GetMapping("/info")
    public ResultInfo<List<BackgroundInfoVo>> getBackGroundInfoById(@RequestParam(value = "id", required = false)Long empId){
        if(empId == null){
            empId = employeeService.getCurrentEmpId();
        }
        List<BackgroundInfo> backInfoById = infoService.getBackInfoById(empId);
        List<BackgroundInfoVo> infoVos = BeanConvertUtils.convertListTo(backInfoById, BackgroundInfoVo::new);
        // 添加关于该条记录的申诉记录
        for (BackgroundInfoVo infoVo : infoVos) {
            infoVo.setAppeals(appealService.getAppealsByBgId(infoVo.getId()));
            // TODO 图片String转Set处理
        }
        return ResultInfoUtil.buildSuccess(getCurrentUrl(),infoVos);
    }
}
